<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="/home/js/jquery-3.3.1.min.js"></script>
    <script src="/layer/layer.js"></script>

    <title>Document</title>
</head>

<body>

    <!-- <a href="{:url('cases','id=5')}">case</a> -->
    <form action="{:url('home/User/userLogin')}" method="post" id="form">

        手机：<input name="phone" type="text" value="">
        <br />
        邮箱：<input name="email" type="text" value="">
        <br />
        密码：<input name="pwd" type="password" value="">
        <br />
        确认密码：<input name="repwd" type="password" value="">
        <br />
        验证码：<input id="code" name="code" type="text" value="" onkeyup="checkCode(this.value)">
        <!-- <img style="display:block;" src="{:captcha_src()}" onclick="this.src='{:captcha_src()}?x='+Math.random();"> -->
        <img src="{:url('home/Home/MakeValidate')}" onclick="this.src='{:url(\'home/Home/MakeValidate\')}?x='+Math.random();">

        <br />
        <p style="display:none" id="yz">验证通过</p>
        <input onclick="login()" disabled type="button" value="登录">
    </form>

</body>
<script>
    function checkCode(val) {
        // alert(val);
        if (val.length == 4) {
            $.ajax({
                type: 'post',
                url: "{:url('home/Home/CheckValidate')}",
                dataType: 'json',
                data: {
                    code: $('#code').val(),
                },
                success: function (res) {
                    // console.log(res)
                    // alert(res.res);
                    if (res.res) {
                        $('#yz').css({
                            'display': 'block'
                        });
                        $(':button').removeAttr('disabled')
                    } else {
                        $('#yz').css({
                            'display': 'none'
                        });
                        $(':button').attr('disabled', 'disabled');
                    }
                }
            })
        } else {
            $('#yz').css({
                'display': 'none'
            });
            $(':button').attr('disabled', 'disabled');
        }
    }

    function login() {
        if (!$(':text').val() || !$(':password').val()) {
            layer.alert('信息错误');
            return false;
        }
        $('#form').submit();
        $.ajax({
            type:'post',
            url:"{:url('home/User/userLogin')}",
            dataType:'json',
            data:{
                phone:$(':text').val(),
                pwd:$(':password').val()
            },
            success:function(res){
                console.log(res)
            }
        })
    }
</script>

</html>